$(function(){
        var inputgoodsname = $("#inputgoodsname");
        var inputgoodsdetail = $("#inputgoodsdetail");
        var inputgoodsimg = $("#inputgoodsimg");
        var inputgoodslabel = $("#inputgoodslabel");
        var btn_yes = $("#yes");
        var btn_no = $("#no");
        // alert(fileToBase64($("#inputgoodsimg")[0].files[0]))

        var selectedOption = $('#inputgoodslabel option:selected').val();
        // alert(selectedOption)

        // 点击确定 将数据传给后端 
        btn_yes.click(function(){
                $.ajax({
                        url:"http://101.33.204.176:8080/product/publish/",
                        type:"POST",
                        async: true,    //是否异步
                        data:{
                                picture:JSON.stringify(fileToBase64($("#inputgoodsimg")[0].files[0])),
                                productName:inputgoodsname,
                                productDesc:inputgoodsdetail,
                                productType:"["+inputgoodslabel+"]",
                                token:"lalalal"
                        },
                        success:function(res){
                                alert("2345678");
                        }
                })
        })

        function fileToBase64(file) {
                return new Promise((resolve, reject) => {
                  const reader = new FileReader();
                  reader.onload = () => {
                    resolve(reader.result.split(",")[1]);
                  };
                  reader.onerror = reject;
                  reader.readAsDataURL(file);
                });
              }
})